<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="户主名称">
              <a-input placeholder="请输入户主名称" v-model="queryParam.householdName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="所属乡镇">
              <j-dict-select-tag placeholder="请选择所属乡镇" v-model="queryParam.fwzId"
                                 dictCode="tb_jrtx_fwz, township_name,id"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="当前状态">
              <j-dict-select-tag placeholder="请选择当前状态" v-model="queryParam.currentStatus"
                                 dictCode="current_status_pkh"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="所属村">
                <j-dict-select-tag placeholder="请选择所属村" v-model="queryParam.fwbId"
                                   dictCode="tb_jrtx_fwb,service_name,id"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="申请金额">
                <a-input placeholder="请输入申请金额" v-model="queryParam.applicationMoney"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.state" dictCode="state"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button :disabled="isDisabledAuth('poorHouseholdLoanList')"  @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('贫困户贷款管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button :disabled="isDisabledAuth('poorHouseholdLoanList')"  type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item :disabled="isDisabledAuth('poorHouseholdLoanList')"  key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在"
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a :disabled="isDisabledAuth('poorHouseholdLoanList')"  @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-popconfirm :disabled="isDisabledAuth('poorHouseholdLoanList')"  title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical"/>
          <a @click="historySearch(record)" type="primary" icon="plus">历史</a>
          <a-divider type="vertical"/>
<!--          <a @click="shenpi(record)" type="primary"  v-has="'permissions:shenpi'" icon="plus">审批</a>-->
          <a @click="shenpi(record)" type="primary" :disabled="isDisabledAuth('poorHouseholdLoanList')"  icon="plus">审批</a>
          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <div style="margin:0 auto; width:550px; height:100px; border:0px solid #F00;font-size: 20px;color : #f00">
      <router-link :to="{name:'jingzhun-industrysupport-HouseholdLoansList'}">
        户贷户用
      </router-link>
      ,发展了
      <router-link :to="{name:'jingzhun-industrysupport-WithPoorEnterprisesList'}">
        3
      </router-link>
      家带贫企业；有
      <router-link :to="{name:'jingzhun-loanmanagement-PoorHouseholdLoanList'}">
        100
      </router-link>
      位农户贷款，有
      <router-link :to="{name:'jingzhun-loanmanagement-CorporateLoansList'}">
        50
      </router-link>
      家企业贷款，有
      <router-link :to="{name:'jingzhun-loanmanagement-EnterpriseIdentificationList'}">
        20
      </router-link>
      家完成带贫企业认定，形成了完善的
      <router-link :to="{name:'jingzhun-loanmanagement-PostCreditManagementList'}">
        金融信贷体系
      </router-link>
    </div>
    <poorHouseholdLoan-modal ref="modalForm" @ok="modalFormOk"></poorHouseholdLoan-modal>
    <ProcessingModal @parentComponentReLoad="parentComponentReLoad" ref="processingModal"></ProcessingModal>
    <!--    <ProcessingListModal ref="processingListModal" ></ProcessingListModal>-->
    <!--    <ProcessingListModal ref="processingListModal" ></ProcessingListModal>-->
    <ProcessingListModal ref="processingListModal"></ProcessingListModal>
    <ProcessFinishListModal ref="processFinishListModal"></ProcessFinishListModal>


  </a-card>
</template>

<script>

    import {JeecgListMixin} from '@/mixins/JeecgListMixin'
    import PoorHouseholdLoanModal from './modules/PoorHouseholdLoanModal'
    import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
    import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
    import ProcessingModal from './modules/ProcessingModal'
    import ProcessingListModal from './modules/ProcessingListModal'
    import ProcessingList from "./ProcessingList";
    import ProcessFinishListModal from "./modules/ProcessFinishListModal";
    import SmallAmountPublicityAccountModal from "./modules/SmallAmountPublicityAccountModal";
    import SmallRecommendationAccountModal from "./modules/SmallRecommendationAccountModal";
    import SmallLoanAccountModal from "./modules/SmallLoanAccountModal";
    import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'

    export default {
        name: "PoorHouseholdLoanList",
        mixins: [JeecgListMixin,DisabledAuthFilterMixin],
        components: {
            ProcessFinishListModal,
            ProcessingListModal,
            ProcessingList,
            ProcessingModal,
            JDictSelectTag,
            PoorHouseholdLoanModal
        },
        data() {
            return {
                description: '贫困户贷款管理管理页面',
                // 表头
                columns: [
                    {
                        title: '#',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: "center",
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        }
                    },
                    {
                        title: '户主名称',
                        align: "center",
                        dataIndex: 'householdName'
                    },
                    {
                        title: '身份证号',
                        align: "center",
                        dataIndex: 'idNumber'
                    },
                    {
                        title: '所属乡镇',
                        align: "center",
                        dataIndex: 'fwzId',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['fwzId'], text + "")
                            }
                        }
                    },
                    {
                        title: '所属村',
                        align: "center",
                        dataIndex: 'fwbId',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['fwbId'], text + "")
                            }
                        }
                    },
                    {
                        title: '申请金额',
                        align: "center",
                        dataIndex: 'applicationMoney'
                    },
                    {
                        title: '申请时间',
                        align: "center",
                        dataIndex: 'applicationDate',
                        customRender: function (text) {
                            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '银行类别',
                        align: "center",
                        dataIndex: 'bankType',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['bankType'], text + "")
                            }
                        }
                    },
                    {
                        title: '当前状态',
                        align: "center",
                        dataIndex: 'currentStatus',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['currentStatus'], text + "")
                            }
                        }
                    }
                    ,
                    {
                        title: '总状态',
                        align: "center",
                        dataIndex: 'state',
                        customRender: (text) => {
                            if (!text) {
                                return ''
                            } else {
                                return filterMultiDictText(this.dictOptions['state'], text + "")
                            }
                        }
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: "center",
                        scopedSlots: {customRender: 'action'},
                    }
                ],
                url: {
                    list: "/loanmanagement/poorHouseholdLoan/list",
                    delete: "/loanmanagement/poorHouseholdLoan/delete",
                    deleteBatch: "/loanmanagement/poorHouseholdLoan/deleteBatch",
                    exportXlsUrl: "/loanmanagement/poorHouseholdLoan/exportXls",
                    importExcelUrl: "loanmanagement/poorHouseholdLoan/importExcel",
                },
                dictOptions: {
                    fwzId: [],
                    fwbId: [],
                    currentStatus: [],
                    state: [],
                }
            }
        },
        computed: {
            importExcelUrl: function () {
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            }
        },
        methods: {
            parentComponentReLoad(data) {
                this.loadData();
            },
            gongShi(record) {
                this.$refs.smallAmountPublicityAccountModal.showGoodsGallery1(record);
            },
            tuiJian(record) {
                this.$refs.smallRecommendationAccountModal.showGoodsGallery1(record);
            },
            fangKuan(record) {
                this.$refs.smallLoanAccountModal.showGoodsGallery1(record);
            },
            shenpi(record) {
                this.$refs.processingModal.showGoodsGallery1(record);
            },
            historySearch(record) {
                //通过record的state 判断跳转哪个modal  state=0（通过）
                if (record.state == 1) {
                    this.$refs.processingListModal.showGoodsGallery1(record);
                } else {
                    this.$refs.processFinishListModal.showGoodsGallery1(record);
                }
            },
            initDictConfig() {
                initDictOptions('bank_type').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'bankType', res.result)
                    }
                })
                initDictOptions('tb_jrtx_fwz, township_name,id').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'fwzId', res.result)
                    }
                })
                initDictOptions('tb_jrtx_fwb,service_name,id').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'fwbId', res.result)
                    }
                })
                initDictOptions('current_status_pkh').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'currentStatus', res.result)
                    }
                })
                initDictOptions('state').then((res) => {
                    if (res.success) {
                        this.$set(this.dictOptions, 'state', res.result)
                    }
                })
            }

        }
    }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>